package br.com.hmm.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * 
 * @author carlos
 * 
 */
public class FabricaConexao {

	private static final String URL = "jdbc:mysql://localhost:3306/mydb";
	private static final String USUARIO = "root";
	private static final String SENHA = "21Cr4zy12";
	private static final String DRIVER = "com.mysql.jdbc.Driver";
	private static FabricaConexao instancia = null;

	/**
	 * 
	 */
	private FabricaConexao() {

	}

	/**
	 * 
	 * @return
	 */
	public static FabricaConexao getInstancia() {

		if (instancia == null) {
			instancia = new FabricaConexao();
		}

		return instancia;
	}

	/**
	 * Cria conexão única com o banco de dados.
	 * 
	 * @return Connection
	 */
	public static Connection conectar() {
		Connection con = null;
		try {
			Class.forName(DRIVER);
			con = DriverManager.getConnection(URL, USUARIO, SENHA);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException sqlexp) {
			sqlexp.printStackTrace();
		}

		return con;

	}

}
